package com.example.servlet.StudentServlet;

import com.example.bean.Student;
import com.example.dao.StudentDao.StudentSearchDao;
import com.example.dao.StudentDao.StudentSearchDaoImp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "SearchServlet", value = "/search")
public class SearchServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取浏览器发来的姓名
        String name = request.getParameter("name");
        System.out.println("获取到的姓名为:"+name);

        //2.将姓名信息打包给Dao
        Student student=new Student(name);
        StudentSearchDao studentSearchDao=new StudentSearchDaoImp();
        studentSearchDao.getStudentSearch(student);

        request.getSession().setAttribute("compare",name);
        response.sendRedirect("searchTarget.jsp");
    }
}
